﻿using UnityEngine;
using System.Collections;

public class OptionButton : MonoBehaviour {
private Vector3 velocity;
	private Vector3 old_position;
	private GameObject[]buttons;
	private GameObject bar;
	private GameManager manager;
    [SerializeField]
    private AudioClip soundClip;
	private void Start(){
		bar=GameObject.FindGameObjectWithTag("bar");
		buttons=new GameObject[]{GameObject.FindGameObjectWithTag("help"),GameObject.FindGameObjectWithTag("setting"),
			GameObject.FindGameObjectWithTag("sound"),GameObject.FindGameObjectWithTag("no_sound"),
			GameObject.FindGameObjectWithTag("music"),GameObject.FindGameObjectWithTag("no_music")};
		manager=GameManager.getInstance();
		old_position=bar.transform.position;	
		b=new ButtonOption(buttons);
	}
	ButtonOption b;
    private void Option(){
        if (manager.Sound)
        {
            PlaySound();
        }
		if(manager.ButtonClick==Click.can_click){
			manager.ButtonClick=Click.can_not_click;
			if(manager.BarShow){
				b.Action();
				manager.BarShow=false;
			}
			manager.ButtonClick=Click.can_click;
		}
      }
	private void Update(){
		if(manager.IsShow){
			bar.transform.position=Vector3.SmoothDamp(bar.transform.position,
                                                      new Vector3(-1.366442f, -2.149176f, 0.5f),
			                                          ref velocity,0.1f);

		}
		if(!manager.IsShow){
			bar.transform.position=
				Vector3.SmoothDamp(bar.transform.position,old_position,ref velocity,0.1f);
			b.Show();
		}
		if ((bar.transform.position == new Vector3(-1.366442f, -2.149176f, 0.5f)) ||
		    (bar.transform.position==old_position)){
			manager.BarShow=true;
			b.Show();
		}

	}
    void PlaySound()
    {
        audio.clip = soundClip;
        audio.Play();
    }
}
